package com.quanyan.travel.component.asyn;

import com.quanyan.common.mail.EmailUtils;
import com.quanyan.travel.service.TravelCacheService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 *  异步调用的service类
 *
 *
 */
@Service("travelAsyncService")
public class TravelAsyncService {

    private static Logger logger = LoggerFactory.getLogger(TravelAsyncService.class);


    /**
     *  户外邮件异常
     *
     * */
    private final static String EMAIL_SUBJECT = ";<户外模块>出现异常,请求路径:";
    private final static String EMAILS = "xiao.lai@quncaotech.com;dongsheng.lin@quncaotech.com;yiqiang.zou@quncaotech.com";


    @Autowired
    private TravelCacheService travelCacheService;



    @Async
    public void sendMail(HttpServletRequest request, String errorMsg) {
        EmailUtils.getInstance().sendHtmlEmails(EMAILS, "<服务器>:"+request.getServerName()+EMAIL_SUBJECT+request.getRequestURI(), errorMsg);
//        EmailUtils.getInstance().sendHtmlEmails(EMAILS, "<服务器>:"+request.getServerName()+EMAIL_SUBJECT+request.getRequestURI(), errorMsg);
    }

    @Async
    public void initOrderRemindAsync(int uid, String orderNo) {
        logger.info("异步调用initOrderRemindAsync方法");
        travelCacheService.initOrderRemindToCache(uid, orderNo);
    }

    @Async
    public void updateOrderRemindAsync(int uid, String orderNo) {
        logger.info("异步调用updateOrderRemindAsync方法");
        travelCacheService.updateOrderRemindToCache(uid, orderNo);
    }

}
